package com.fmi.cloud.guide;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.ViewGroup;

import com.fmi.cloud.R;

import java.util.ArrayList;

public class GuideFragmentActivity extends FragmentActivity {

    private ArrayList<Fragment> mFragmentList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_fragment);
        initFragment();
        initViewPager();
    }

    private void initFragment() {
        GuideFragment1 f1 = new GuideFragment1();
        GuideFragment2 f2 = new GuideFragment2();
        GuideFragment3 f3 = new GuideFragment3();
        mFragmentList.add(f1);
        mFragmentList.add(f2);
        mFragmentList.add(f3);
    }

    private void initViewPager() {
        ViewPager vPage = (ViewPager) findViewById(R.id.viewpager);
        FragmentManager fragmentManager = getSupportFragmentManager();
        vPage.setAdapter(new ViewPageAdapter(fragmentManager, mFragmentList));
    }

    private class ViewPageAdapter extends FragmentStatePagerAdapter {
        ArrayList<Fragment> mFragmentList;

        ViewPageAdapter(FragmentManager fm,
                        ArrayList<Fragment> fragmentList) {
            super(fm);
            this.mFragmentList = fragmentList;
        }

        @Override
        public Fragment getItem(int arg0) {
            return this.mFragmentList.get(arg0);
        }

        @Override
        public int getCount() {
            return this.mFragmentList.size();
        }

        @Override
        public Object instantiateItem(ViewGroup arg0, int arg1) {
            return super.instantiateItem(arg0, arg1);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            super.destroyItem(container, position, object);
        }
    }
}

